package tio.study.showcase.client.handler;

import lombok.extern.slf4j.Slf4j;
import org.tio.core.ChannelContext;
import org.tio.core.Tio;
import org.tio.utils.json.Json;
import tio.study.showcase.common.ShowcasePacket;
import tio.study.showcase.common.intf.AbsShowcaseBsHandler;
import tio.study.showcase.common.packets.JoinGroupRespBody;

/**
 * @author tanyaowu
 * 2017年3月27日 下午9:51:28
 */
@Slf4j
public class JoinGroupRespHandler extends AbsShowcaseBsHandler<JoinGroupRespBody> {

    /**
     * @author: tanyaowu
     */
    public JoinGroupRespHandler() {
    }

    /**
     * @return
     * @author: tanyaowu
     */
    @Override
    public Class<JoinGroupRespBody> bodyClass() {
        return JoinGroupRespBody.class;
    }

    /**
     * @param packet
     * @param bsBody
     * @param channelContext
     * @return
     * @throws Exception
     * @author tanyaowu
     */
    @Override
    public Object handler(ShowcasePacket packet, JoinGroupRespBody bsBody, ChannelContext channelContext) throws Exception {
        log.info("收到进群响应消息:{}", Json.toJson(bsBody));
        if (JoinGroupRespBody.Code.SUCCESS.equals(bsBody.getCode())) {
            Tio.bindGroup(channelContext, bsBody.getGroup());
            log.info("进入群组[{}]成功", bsBody.getGroup());
        }
        return null;
    }

}
